package dome1;

import java.util.Arrays;

//对象之间的大小关系比较

public class TestDome1 {
    //冒泡排序
    public static void bubblesort(Comparable[] comparables){
        for(int i = 0;i<comparables.length-1; i++){
            for(int j = 0;j<comparables.length-1;j++){
                if (comparables[j].compareTo(comparables[j+1])>0) {
                    //交换
                    Comparable tmp = comparables[j];
                    comparables[j] =  comparables[j+1];
                    comparables[j+1] = tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("小明",15,60);
        students[1] = new Student("小红",16,70);
        students[2] = new Student("小军",15,68);
        bubblesort(students);
        System.out.println(Arrays.toString(students));

    }



    public static void main3(String[] args) {
        Person[] people = new Person[3];
        people[0] = new Person("yyx",19,66.66);
        people[1] = new Person("xxx",18,77.77);
        people[2] = new Person("xxy",17,88.88);
        Arrays.sort(people);//数组排序
        System.out.println(Arrays.toString(people));

    }



    public static void main2(String[] args) {
        Student student1 = new Student("叶叶",18,80.5);
        Student student2 = new Student("瑾瑾",19,90);
        AgeComparator ageComparator = new AgeComparator();
        int ret = ageComparator.compare(student1,student2);
        if(ret>0){
            System.out.println("年龄关系:s1>s2");
        }else {
            System.out.println("年龄关系:s1<s2");
        }
        NameComparator nameComparator = new NameComparator();
        int ret2 = nameComparator.compare(student1,student2);
        if(ret>0){
            System.out.println("姓名关系:s1>s2");
        }else {
            System.out.println("姓名关系:s1<s2");
        }
        ScoreComparator scoreComparator = new ScoreComparator();
        int ret3 = scoreComparator.compare(student1,student2);
        if(ret>0){
            System.out.println("成绩关系:s1>s2");
        }else {
            System.out.println("成绩关系:s1<s2");
        }


    }
    public static void main1(String[] args) {
        Student student1 = new Student("叶叶",18,80.5);
        Student student2 = new Student("瑾瑾",19,90);
        //System.out.println(student1.compareTo(student2));
        if(student1.compareTo(student2)>0){
            System.out.println(student1.name+"的年龄更大");
        } else if (student1.compareTo(student2)<0) {
            System.out.println(student2.name+"的年龄更大");
        }else {
            System.out.println("两人年龄一样大");
        }

        Person p1 = new Person("yy",10,55.33);
        Person p2 = new Person("jj",9,33.55);
        if(p1.compareTo(p2)>0){
            System.out.println(p1.name+"的成绩更高");
        } else if (p1.compareTo(p2)<0) {
            System.out.println(p1.name+"的成绩更低");
        }else {
            System.out.println("两人成绩一样");
        }

        }
    }
